package com.dd.common.dto.system.user;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.List;

/**
 * 系统用户更新DTO
 */
@Schema(description = "系统用户更新DTO")
@Data
public class SysUserUpdateDTO implements Serializable {

    @NotNull(message = "用户ID不能为空")
    @Schema(description = "系统用户ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
    @Min(value = 1, message = "ID必须是正整数")
    private Long id;

    @Schema(description = "账号用户名（仅限字母、数字、下划线）", example = "admin_user_1")
    @Pattern(regexp = "^[a-zA-Z0-9_]{4,30}$", message = "用户名必须由4-30位字母、数字或下划线组成")
    private String username;

    @Email(message = "邮箱格式不正确")
    @Schema(description = "邮箱地址", example = "user@example.com")
    private String email;

    @Pattern(regexp = "^\\+?[0-9]{10,15}$", message = "手机号格式不正确，支持国际格式")
    @Schema(description = "手机号码（可选，支持国际号码）", example = "+8613812345678")
    private String phone;

    @Schema(description = "头像")
    private String avatar;

    @Schema(description = "昵称", example = "如烟大帝")
    private String nickname;
    @Schema(description = "真实姓名", example = "柳如烟")
    private String realName;
    @Schema(description = "性别（0-未知，1-男，2-女）", example = "1")
    @Range(min = 0, max = 2, message = "性别只能是0、1或2")
    private Integer gender;
    @Schema(description = "状态（0-禁用，1-正常）", example = "1")
    @Range(min = 0, max = 1, message = "状态只能是0或1")
    private Integer status;

    /**
     * 更新DTO中的数组：null 表示不更新, [] 表示清空, [1,2] 表示更新
     */
//    @NotNull(message = "角色ID列表不能为null") 要允许 roleIds 为 null，表示不更新
//    @NotEmpty(message = "角色ID列表不能为空") 要允许 roleIds 为空 []，表示清空
    // 对 List 内容验证，要注意 @Min 不验证 null，也就是 [null] 会允许传入。
    // 因此要加 @NotNull
    @Schema(description = "角色ID列表", example = "[1,2]")
    private List<@NotNull(message = "ID不能为null") @Min(value = 1, message = "ID必须是正整数") Long> roleIds;

    @Schema(description = "部门ID列表", example = "[1,2]")
    private List<@NotNull(message = "ID不能为null") @Min(value = 1, message = "ID必须是正整数") Long> deptIds;

    @Schema(description = "职位ID列表", example = "[1,2]")
    private List<@NotNull(message = "ID不能为null") @Min(value = 1, message = "ID必须是正整数") Long> positionIds;
}
